//
//  ViewController.swift
//  ViewAnimation
//
//  Created by 涂晶 on 16/6/8.
//  Copyright © 2016年 TuJing. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    // MARK :IB outlets
    
    @IBOutlet weak var testLabel: UILabel!
    @IBOutlet weak var userName: UITextField!
    @IBOutlet weak var password: UITextField!
    
    @IBOutlet weak var cloud2: UIImageView!
    @IBOutlet weak var cloud1: UIImageView!
    @IBOutlet weak var cloud3: UIImageView!
    @IBOutlet weak var cloud4: UIImageView!
    //MARK : view controller methods

    override func viewDidLoad()

    {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(animated: Bool)
    {
        testLabel.center.x -= view.bounds.width
        userName.center.x -= view.bounds.width
        password.center.x -= view.bounds.width
        
        cloud1.alpha = 0.0
        cloud2.alpha = 0.0
        cloud3.alpha = 0.0
        cloud4.alpha = 0.0
    }
    
    override func viewDidAppear(animated: Bool)
    {
        UIView.animateWithDuration(0.5, animations: {
            self.testLabel.center.x += self.view.bounds.width
        })
        
        UIView.animateWithDuration(0.5, delay: 0.3, options: [], animations: {
            self.userName.center.x += self.view.bounds.width
            }, completion: nil)
        
        UIView.animateWithDuration(0.5, delay: 0.4, options: [], animations: {
            self.password.center.x += self.view.bounds.width
            }, completion: nil)
        
        UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {
            self.cloud1.alpha = 0.5
            }, completion: nil)
        
        UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {
            self.cloud2.alpha = 0.7
            }, completion: nil)
        
        UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {
            self.cloud3.alpha = 0.9
            }, completion: nil)
        
        UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {
            self.cloud4.alpha = 1.1
            }, completion: nil)
    }
}

